package com.project.controller;

import com.project.bean.UserBean;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("test")
public class TestController {

    @RequestMapping("speak")
    public static String speak(HttpServletRequest req){
        // 绑定共享数据，在request中绑定的共享数据，作用域在一次请求范围之内
        req.setAttribute("name","tom");
        req.setAttribute("age",30);
        req.setAttribute("user",new UserBean(1,"张三","13203928392"));
        List<UserBean> list = new ArrayList<>();
        list.add(new UserBean(5,"刘三","13039847384"));
        list.add(new UserBean(6,"何昆","15039284938"));
        list.add(new UserBean(8,"胡东","18940394849"));

        req.setAttribute("userList",list);

        //请求转发到页面
        return "/test.html";
    }
}
